package com.cdwm.mrp.controller.view;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cdwm.mrp.domain.po.InterfaceDoc;
import com.cdwm.mrp.domain.po.Project;
import com.cdwm.mrp.service.InterfaceDocService;
import com.cdwm.mrp.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @version v1.0
 * @Author: lyw
 * @Date: 2021/8/4
 */
@Controller
@RequestMapping("/project")
public class ProjectControllerView {
    @Autowired
    private ProjectService projectService;

    @Autowired
    private InterfaceDocService interfaceDocService;

    @GetMapping("/view/system/projectView")
    public String projectMainView(){
        return "view/system/project/project";
    }

    @GetMapping("/view/system/add")
    public String addProjectView(){
        return "view/system/project/add";
    }

    @GetMapping("/view/system/edit/{id}")
    public String editProjectView(@PathVariable Long id, Model model){
        Project project = projectService.getById(id);

        model.addAttribute("project",project);
        return "view/system/project/edit";
    }

    /**
     * 上传接口文档
     * @param id
     * @param model
     * @return
     */
    @GetMapping("/view/system/upload/{id}")
    public String uploadInterfaceDocView(@PathVariable Long id,Model model){
        model.addAttribute("projectId",id);
        return "view/system/project/upload";
    }

    /**
     *查看接口文档
     * @param id
     * @param model
     * @return
     */
    @GetMapping("/view/system/queryInterfaceDoc/{id}")
    public String queryInterfaceDocView(@PathVariable Integer id,Model model){
        QueryWrapper<InterfaceDoc> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("project_id",id);
        List<InterfaceDoc> InterfaceDocList = interfaceDocService.list(queryWrapper);
        model.addAttribute("InterfaceDocList",InterfaceDocList);
        return "view/system/project/interfaceDoc";
    }
}
